package com.ruoyi.control.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.deviceControl.dto.LinkageControlDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.deviceControl.domain.LinkageControl;
import com.ruoyi.deviceControl.service.ILinkageControlService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 联动控制Controller
 * 
 * @author ruoyi
 * @date 2024-12-14
 */
@RestController
@RequestMapping("/linkageControl/linkageControl")
public class LinkageControlController extends BaseController
{
    @Autowired
    private ILinkageControlService linkageControlService;

    /**
     * 查询联动控制列表
     */
    @PreAuthorize("@ss.hasPermi('linkageControl:linkageControl:list')")
    @GetMapping("/list")
    public TableDataInfo list(LinkageControl linkageControl)
    {
        startPage();
        List<LinkageControl> list = linkageControlService.selectLinkageControlList(linkageControl);
        return getDataTable(list);
    }

    /**
     * 查询联动控制列表by分级报警id
     */
    @PreAuthorize("@ss.hasPermi('linkageControl:linkageControl:list')")
    @GetMapping("/listByAlarmId/{alarmId}")
    public TableDataInfo listByAlarmId(@PathVariable("alarmId") String alarmId)
    {
        startPage();
        List<LinkageControlDto> list = linkageControlService.selectLinkageControlListByAlarmId(alarmId);
//        String ids[] = {"1317454623766761472","1317452938805792768"};
//        String s = linkageControlService.selectLinkageControlListByAlarmIds(ids);
//        System.out.println("2024/12/18:" + s);
        return getDataTable(list);
    }

    /**
     * 查询联动控制列表的设备by分级报警ids
     */
    @PreAuthorize("@ss.hasPermi('linkageControl:linkageControl:list')")
    @GetMapping("/listByAlarmIds/{alarmIds}")
    public String  listByAlarmIds(@PathVariable String[] alarmIds)
    {
        String deviceIds = linkageControlService.selectLinkageControlListByAlarmIds(alarmIds);
        return deviceIds;
    }


    /**
     * 导出联动控制列表
     */
    @PreAuthorize("@ss.hasPermi('linkageControl:linkageControl:export')")
    @Log(title = "联动控制", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LinkageControl linkageControl)
    {
        List<LinkageControl> list = linkageControlService.selectLinkageControlList(linkageControl);
        ExcelUtil<LinkageControl> util = new ExcelUtil<LinkageControl>(LinkageControl.class);
        util.exportExcel(response, list, "联动控制数据");
    }

    /**
     * 获取联动控制详细信息
     */
    @PreAuthorize("@ss.hasPermi('linkageControl:linkageControl:query')")
    @GetMapping(value = "/{linkageControlId}")
    public AjaxResult getInfo(@PathVariable("linkageControlId") String linkageControlId)
    {
        return success(linkageControlService.selectLinkageControlByLinkageControlId(linkageControlId));
    }

    /**
     * 新增联动控制
     */
    @PreAuthorize("@ss.hasPermi('linkageControl:linkageControl:add')")
    @Log(title = "联动控制", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LinkageControl linkageControl)
    {
        return toAjax(linkageControlService.insertLinkageControl(linkageControl));
    }

    /**
     * 修改联动控制
     */
    @PreAuthorize("@ss.hasPermi('linkageControl:linkageControl:edit')")
    @Log(title = "联动控制", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LinkageControl linkageControl)
    {
        return toAjax(linkageControlService.updateLinkageControl(linkageControl));
    }

    /**
     * 删除联动控制
     */
    @PreAuthorize("@ss.hasPermi('linkageControl:linkageControl:remove')")
    @Log(title = "联动控制", businessType = BusinessType.DELETE)
	@DeleteMapping("/{linkageControlIds}")
    public AjaxResult remove(@PathVariable String[] linkageControlIds)
    {
        return toAjax(linkageControlService.deleteLinkageControlByLinkageControlIds(linkageControlIds));
    }
}
